home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / netzwerk / magplip / source / port.asm < prev    next >
Assembly Source File  |  1996-02-26  |  11KB  |  317 lines

  1. ;
  2. ;  $VER: port.asm 1.4 (30 Dec 1995)
  3. ;
  4. ;  magplip.device - Parallel Line Internet Protocol
  5. ;
  6. ;  Assembler routines for efficient port handling.
  7. ;
  8. ;  Original code written by Oliver Wagner and Michael Balzer.
  9. ;
  10. ;  This version has been completely reworked by Marius Gröger, introducing
  11. ;  slight protocol changes. The new source is a lot better organized and
  12. ;  maintainable.
  13. ;
  14. ;  Additional changes and code cleanup by Jan Kratochvil and Martin Mares.
  15. ;  The new source is significantly faster and yet better maintainable.
  16. ;
  17. ;  (C) Copyright 1993-1994 Oliver Wagner & Michael Balzer
  18. ;  (C) Copyright 1995 Jan Kratochvil & Martin Mares
  19. ;  (C) Copyright 1995 Marius Gröger
  20. ;      All Rights Reserved
  21. ;
  22. ;  $HISTORY:
  23. ;
  24. ;  30 Dec 1995 : 001.004 :  support for single frame buffer
  25. ;  05 Dec 1995 : 001.003 :  + short branches explicitly coded as such
  26. ;                           + some condition jumps which were effectively
  27. ;                             unconditional changed to bra's
  28. ;  30 Aug 1995 : 001.002 :  support for timer-timed timeout :-)
  29. ;  20 Aug 1995 : 001.001 :  + removed need for conditional compiling, as we
  30. ;                             we want a generic, symmetrical code
  31. ;                           + in interrupt handlers, A6 points already to
  32. ;                             SysBase
  33. ;                           + using JSRLIB/JMPLIB macros
  34. ;                           + removed implicit some assumptions on the values
  35. ;                             behind symbolic names
  36. ;  13 Feb 1995 : 001.000 :  created (in fact manually compiled from 'C'-
  37. ;                           original) (jk/mm)
  38. ;
  39.       section "text",code
  40.  
  41.       IFND HARDARE_CIA_I
  42.       include "hardware/cia.i"
  43.       ENDC
  44.  
  45.       IFND EXEC_MACROS_I
  46.       include "exec/macros.i"
  47.       ENDC
  48.  
  49.       IFND MAGPLIP_I
  50.       include "magplip.i"
  51.       ENDC
  52.  
  53. ciaa     equ     $bfe001
  54. ciab     equ     $bfd000
  55. BaseA5   equ     ciab+ciapra
  56.  
  57.       xref    _CRC16
  58.  
  59.       xdef    _interrupt
  60.       xdef    _hwsend
  61.       xdef    _hwrecv
  62.  
  63. ;----------------------------------------------------------------------------
  64. ;
  65. ; NAME
  66. ;     interrupt() - ICR FLG interrupt handler
  67. ;
  68. ; SYNOPSIS
  69. ;     void interrupt(struct PLIPBase *)
  70. ;                    A1
  71. ;
  72. ; FUNCTION
  73. ;     This is called from CIA resource on the receipt of an parallel port
  74. ;     FLG line interrupt. This is the case if the other side starts
  75. ;     transmission and writes the first byte to our port.
  76. ;
  77. ;     We recognise this here and propagate the information to the server
  78. ;     task by Signal()ing it and by setting the PLIPB_RECEIVING bit
  79. ;     in the flags field.
  80. ;
  81. _interrupt:
  82.         btst    #PLIPB_RECEIVING,pb_Flags(a1)
  83.         bne.s   skipint
  84.         move.b  pb_HandshakeBit+HS_LINE(a1),d0
  85.         btst    d0,ciab+ciapra
  86.         beq.s   skipint
  87.         bset    #PLIPB_RECEIVING,pb_Flags(a1)
  88.         move.l  pb_IntSigMask(a1),d0
  89.         move.l  pb_Server(a1),a1
  90.         JMPLIB  Signal
  91. skipint rts
  92.  
  93. ;----------------------------------------------------------------------------
  94. ;
  95. ; NAME
  96. ;     hwsend() - low level send routine
  97. ;
  98. ; SYNOPSIS
  99. ;     void hwsend(struct PLIPBase *)
  100. ;                  A0
  101. ;
  102. ; FUNCTION
  103. ;     This routine sends the PLIPBase->pb_Frame to the other side. It
  104. ;     cares for CRC encoding, if wanted. The frame header will be
  105. ;     set up except of the pf_Size field, which must be pre-initialized.
  106. ;
  107. _hwsend:
  108.          movem.l  d2-d7/a2-a6,-(sp)
  109.          move.l   a0,a2                               ; a2 = PLIPBase
  110.          moveq    #FALSE,d2                           ; d2 = return value
  111.          moveq    #0,d3
  112.          move.l   d3,d4
  113.          move.b   pb_HandshakeBit+HS_REQUEST(a2),d3   ; d3 = HS_REQUEST
  114.          move.b   pb_HandshakeBit+HS_LINE(a2),d4      ; d4 = HS_LINE
  115.          move.l   pb_Frame(a2),a4                     ; a4 = Frame
  116.  
  117.          ;
  118.          ; CRC wanted ?
  119.          ;
  120.          btst     #PLIPB_SENDCRC,pb_Flags(a2)
  121.          beq.s    hww_NoCRC
  122.          ; yes
  123.          move.w   #SYNCWORD_CRC,pf_Sync(a4)
  124.          lea      PLIPFrame_SIZE(a4),a0
  125.          move.w   pf_Size(a4),d0
  126.          subq.w   #PKTFRAMESIZE_2,d0
  127.          jsr      _CRC16(pc)
  128.          move.w   d0,pf_CRC(a4)
  129.          bra.s    hww_CRC
  130.  
  131. hww_NoCRC:
  132.          move.w   #SYNCWORD_NOCRC,pf_Sync(a4)
  133.  
  134. hww_CRC  move.l   pb_CIAABase(a2),a6
  135.          moveq    #CIAICRF_FLG,d0
  136.          JSRLIB   AbleICR                             ; DISABLEINT
  137.          lea      BaseA5,a5
  138.          st       ciaa+ciaddrb-BaseA5(a5)             ; SETCIAOUTPUT
  139.          move.b   (a5),d7                             ; SAMPLEINPUT, d7 = State
  140.          move.l   a4,a3
  141.          move.w   pf_Size(a4),d6
  142.          addq.w   #PKTFRAMESIZE_1-2,d6
  143.          move.b   (a3)+,ciaa+ciaprb-BaseA5(a5)        ; WRITECIA *p++
  144. hww_LoopShake1:
  145.          move.b   (a5),d0                             ; ciab+ciapra
  146.          eor.b    d7,d0
  147.          btst     d4,d0                               ; WAITINPUTTOGGLE
  148.          bne.s    hww_cont1
  149.          tst.b    pb_TimeoutSet(a2)
  150.          beq.s    hww_LoopShake1
  151.          bra.s    hww_TimedOut
  152. hww_cont1:
  153.          eor.b    d0,d7
  154.  
  155. hww_MainLoop:
  156.          move.b   (a3)+,ciaa+ciaprb-BaseA5(a5)        ; WRITECIA *p++
  157.          bchg     d3,(a5)                             ; OUTPUTTOGGLE
  158. hww_LoopShake2:
  159.          move.b   (a5),d0                             ; ciab+ciapra
  160.          eor.b    d7,d0
  161.          btst     d4,d0                               ; WAITINPUTTOGGLE
  162.          bne.s    hww_cont2
  163.          tst.b    pb_TimeoutSet(a2)
  164.          beq.s    hww_LoopShake2
  165.          bra.s    hww_TimedOut
  166. hww_cont2:
  167.          eor.b    d0,d7
  168.          dbra     d6,hww_MainLoop
  169.          moveq    #TRUE,d2                            ; rc = TRUE
  170. hww_TimedOut:
  171.          sf       ciaa+ciaddrb-BaseA5(a5)             ; SETCIAINPUT
  172.          bclr     d3,(a5)                             ; CLEARREQUEST ciab+ciapra
  173.          moveq    #CIAICRF_FLG,d0
  174.          JSRLIB   SetICR                              ; CLEARINT
  175.          move.w   #CIAICRF_FLG|CIAICRF_SETCLR,d0
  176.          JSRLIB   AbleICR                             ; ENABLEINT
  177.  
  178.          move.l   d2,d0                               ; return rc
  179.          movem.l  (sp)+,d2-d7/a2-a6
  180. Return   rts
  181.  
  182.  
  183. ;----------------------------------------------------------------------------
  184. ;
  185. ; NAME
  186. ;     hwrecv() - low level receive routine
  187. ;
  188. ; SYNOPSIS
  189. ;     void hwrecv(struct PLIPBase *)
  190. ;                 A0
  191. ;
  192. ; FUNCTION
  193. ;     This routine receives a magPLIP frame and stores it into
  194. ;     PLIPBase->pb_Frame. It cares for CRC decoding, if the incoming
  195. ;     packet is encoded. The pf_Size field will indicate the length
  196. ;     of the received data.
  197. ;
  198. _hwrecv:
  199.          movem.l  d2-d7/a2-a6,-(sp)
  200.          move.l   a0,a2                               ; a2 = PLIPBase
  201.          moveq    #FALSE,d5                           ; d5 = return value
  202.          move.l   pb_CIAABase(a2),a6                  ; a6 = CIABase
  203.          moveq    #0,d3
  204.          move.l   d3,d2
  205.          move.b   pb_HandshakeBit+HS_REQUEST(a2),d3   ; d3 = HS_REQUEST
  206.          move.b   pb_HandshakeBit+HS_LINE(a2),d2      ; d2 = HS_LINE
  207.          lea      BaseA5,a5                           ; a5 = ciab+ciapra
  208.          move.l   pb_Frame(a2),a4                     ; a4 = Frame
  209.  
  210.          moveq    #CIAICRF_FLG,d0
  211.          JSRLIB   AbleICR                             ; DISABLEINT
  212.  
  213.          move.b   (a5),d7                             ; SAMPLEINPUT
  214.          cmp.b    #SYNCBYTE_HEAD,ciaa+ciaprb-BaseA5(a5) ; READCIABYTE
  215.          bne      hwr_TimedOut
  216.  
  217.          bchg     d3,(a5)                             ; OUTPUTTOGGLE
  218. hwr_LoopShake1:
  219.          move.b   (a5),d0                             ; ciab+ciapra
  220.          eor.b    d7,d0
  221.          btst     d2,d0                               ; WAITINPUTTOGGLE
  222.          bne.s    hwr_cont1
  223.          tst.b    pb_TimeoutSet(a2)
  224.          beq.s    hwr_LoopShake1
  225.          bra      hwr_TimedOut
  226. hwr_cont1:
  227.          eor.b    d0,d7
  228.          move.b   ciaa+ciaprb-BaseA5(a5),d4           ; READCIABYTE
  229.          bchg     d3,(a5)                             ; OUTPUTTOGGLE
  230.          move.b   d4,d0
  231.          subq.b   #SYNCBYTE_CRC,d0
  232.          bcs.s    hwr_TimedOut
  233.          subq.b   #SYNCBYTE_NOCRC,d0
  234.          bcc.s    hwr_TimedOut
  235.          lea      pf_Size(a4),a3
  236.  
  237.          ; Read 1st length byte
  238.          ;
  239. hwr_LoopShake2
  240.          move.b   (a5),d0                             ; ciab+ciapra
  241.          eor.b    d7,d0
  242.          btst     d2,d0                               ; WAITINPUTTOGGLE
  243.          bne.s    hwr_cont2
  244.          tst.b    pb_TimeoutSet(a2)
  245.          beq.s    hwr_LoopShake2
  246.          bra.s    hwr_TimedOut
  247. hwr_cont2:
  248.          eor.b    d0,d7
  249.          move.b   ciaa+ciaprb-BaseA5(a5),(a3)+        ; READCIABYTE
  250.          bchg     d3,(a5)                             ; OUTPUTTOGGLE
  251.  
  252.          ; Read 2nd length byte
  253.          ;
  254. hwr_LoopShake3:
  255.          move.b   (a5),d0                             ; ciab+ciapra
  256.          eor.b    d7,d0
  257.          btst     d2,d0                               ; WAITINPUTTOGGLE
  258.          bne.s    hwr_cont3
  259.          tst.b    pb_TimeoutSet(a2)
  260.          beq.s    hwr_LoopShake3
  261.          bra.s    hwr_TimedOut
  262. hwr_cont3:
  263.          eor.b    d0,d7
  264.          move.b   ciaa+ciaprb-BaseA5(a5),(a3)+        ; READCIABYTE
  265.          bchg     d3,(a5)                             ; OUTPUTTOGGLE ciab+ciapra
  266.  
  267.          move.w   -2(a3),d6                           ; = length
  268.          subq.w   #PKTFRAMESIZE_2,d6
  269.          bcs.s    hwr_TimedOut
  270.          cmp.w    pb_MTU+2(a2),d6
  271.          bhi.s    hwr_TimedOut
  272.          addq.w   #PKTFRAMESIZE_2-1,d6
  273.  
  274.          ; Read main packet body
  275.          ;
  276. hwr_MainLoop:
  277. hwr_LoopShake4:
  278.          move.b   (a5),d0                             ; ciab+ciapra
  279.          eor.b    d7,d0
  280.          btst     d2,d0
  281.          bne.s    hwr_cont4
  282.          tst.b    pb_TimeoutSet(a2)
  283.          beq.s    hwr_LoopShake4
  284.          bra.s    hwr_TimedOut
  285. hwr_cont4:
  286.          eor.b    d0,d7
  287.          move.b   ciaa+ciaprb-BaseA5(a5),(a3)+        ; READCIABYTE
  288.          bchg     d3,(a5)                             ; OUTPUTTOGGLE ciab+ciapra
  289.          dbra     d6,hwr_MainLoop
  290.  
  291. hwr_DoneRead:
  292.          subq.b   #SYNCBYTE_CRC,d4
  293.          bne.s    hwr_ReadOkay
  294.          lea      PLIPFrame_SIZE(a4),a0
  295.          move.w   pf_Size(a4),d0
  296.          subq.w   #PKTFRAMESIZE_2,d0
  297.          jsr      _CRC16(pc)
  298.          cmp.w    pf_CRC(a4),d0
  299.          bne.s    hwr_TimedOut
  300.  
  301. hwr_ReadOkay:
  302.          moveq    #TRUE,d5
  303. hwr_TimedOut:
  304.          bclr     #PLIPB_RECEIVING,pb_Flags(a2)
  305.          sf       ciaa+ciaddrb-BaseA5(a5)             ; SETCIAINPUT
  306.          bclr     d3,(a5)                             ; CLEARREQUEST ciab+ciapra
  307.          moveq    #CIAICRF_FLG,d0
  308.          JSRLIB   SetICR                              ; CLEARINT
  309.          move.w   #CIAICRF_FLG|CIAICRF_SETCLR,d0
  310.          JSRLIB   AbleICR                             ; ENABLEINT
  311.  
  312.          move.l   d5,d0                               ; return value
  313.          movem.l  (sp)+,d2-d7/a2-a6
  314.          rts
  315.  
  316.          end
  317.